import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { getWeekMonthQuarterYear } from '/@/utils';
import { list as ownersList } from './WmsCargoOwners.api';
import { list as brandList } from './WmsProductBrand.api';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '货主',
    align: 'center',
    dataIndex: 'ownerName',
  },
  {
    title: '商品名称',
    align: 'center',
    dataIndex: 'productName',
  },
  {
    title: '品牌',
    align: 'center',
    dataIndex: 'productBrandName',
  },
  {
    title: '商品规格',
    align: 'center',
    dataIndex: 'productSpec',
  },
  {
    title: '计量单位',
    align: 'center',
    dataIndex: 'unit',
  },
  {
    title: 'sku编码',
    align: 'center',
    dataIndex: 'productCode',
  },

  {
    title: '商品批次',
    align: 'center',
    dataIndex: 'productBatch',
  },
  {
    title: '商品条码',
    align: 'center',
    dataIndex: 'productBarcode',
  },
  {
    title: '宽',
    align: 'center',
    dataIndex: 'width',
  },
  {
    title: '长',
    align: 'center',
    dataIndex: 'length',
  },
  {
    title: '高',
    align: 'center',
    dataIndex: 'height',
  },
  {
    title: '体积',
    align: 'center',
    dataIndex: 'volume',
  },
  {
    title: '毛重',
    align: 'center',
    dataIndex: 'grossWeight',
  },
  {
    title: '净重',
    align: 'center',
    dataIndex: 'netWeight',
  },
  {
    title: '商品一级分类',
    align: 'center',
    dataIndex: 'categoryName',
  },
  {
    title: '包装规格',
    align: 'center',
    dataIndex: 'packagingSpec',
  },
  {
    title: '养护周期(天)',
    align: 'center',
    dataIndex: 'maintenanceCycle',
  },
  {
    title: '保质期(天)',
    align: 'center',
    dataIndex: 'shelfLife',
  },

  {
    title: '是否保质期管控',
    align: 'center',
    dataIndex: 'isExpiryControlled',
  },
  {
    title: '状态',
    align: 'center',
    dataIndex: 'status_dictText',
  },
  {
    title: '供应商条码',
    align: 'center',
    dataIndex: 'supplierBarcode',
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '货主',
    field: 'ownerId',
    component: 'ApiSelect',
    componentProps: {
      api: ownersList,
      resultField: 'records',
      labelField: 'ownerName',
      valueField: 'id',
    },
  },
  {
    label: 'sku编码',
    field: 'productCode',
    component: 'Input',
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  // 第1行：货主、商品名称、品牌
  {
    label: '货主',
    field: 'ownerId',
    component: 'ApiSelect',
    componentProps: {
      api: ownersList,
      resultField: 'records',
      labelField: 'ownerName',
      valueField: 'id',
    },
    dynamicRules: () => {
      return [{ required: true, message: '请选择货主!' }];
    },
  },
  {
    label: '商品名称',
    field: 'productName',
    component: 'Input',
    dynamicRules: () => {
      return [{ required: true, message: '请输入商品名称!' }];
    },
  },
  {
    label: '品牌',
    field: 'productBrand',
    component: 'ApiSelect',
    componentProps: {
      api: brandList,
      resultField: 'records',
      labelField: 'name',
      valueField: 'id',
    },
  },
  // 第2行：商品规格、单位、sku编码
  {
    label: '商品规格',
    field: 'productSpec',
    component: 'Input',
  },
  {
    label: '单位',
    field: 'unit',
    component: 'Input',
  },
  {
    label: 'sku编码',
    field: 'productCode',
    component: 'Input',
    dynamicRules: () => {
      return [{ required: true, message: '请输入sku编码!' }];
    },
  },
  // 第3行：商品批次、商品条码、供应商条码
  {
    label: '商品批次',
    field: 'productBatch',
    component: 'Input',
  },
  {
    label: '商品条码',
    field: 'productBarcode',
    component: 'Input',
    dynamicDisabled: () => true,
  },
  {
    label: '供应商条码',
    field: 'supplierBarcode',
    component: 'Input',
  },
  // 第4行：体积、毛重、净重
  {
    label: '体积',
    field: 'volume',
    component: 'InputNumber',
  },
  {
    label: '毛重',
    field: 'grossWeight',
    component: 'InputNumber',
  },
  {
    label: '净重',
    field: 'netWeight',
    component: 'InputNumber',
  },
  // 第5行：商品分类、包装规格、养护周期(天)
  {
    label: '商品分类',
    field: 'categoryId',
    component: 'JTreeSelect',
    componentProps: {
      dict: 'wms_product_categories,category_name,id',
      pidField: 'parent_id',
      pidValue: '0',
      hasChildField: 'has_child',
    },
    dynamicRules: () => {
      return [{ required: true, message: '请选择商品分类!' }];
    },
  },
  {
    label: '包装规格',
    field: 'packagingSpec',
    component: 'Input',
  },
  {
    label: '养护周期(天)',
    field: 'maintenanceCycle',
    component: 'InputNumber',
  },
  // 第6行：保质期(天)、是否保质期管控、状态
  {
    label: '保质期(天)',
    field: 'shelfLife',
    component: 'InputNumber',
  },
  {
    label: '是否保质期管控',
    field: 'isExpiryControlled',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'yn',
    },
  },
  {
    label: '状态',
    field: 'status',
    component: 'JDictSelectTag',
    componentProps: {
      options: [
        { label: '启用', value: '1' },
        { label: '不启用', value: '0' },
      ],
    },
    dynamicRules: () => {
      return [{ required: true, message: '请选择状态!' }];
    },
  },
  // 隐藏主键
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

// 高级查询数据
export const superQuerySchema = {
  productName: { title: '商品名称', order: 0, view: 'text', type: 'string' },
  ownerId: { title: '货主id', order: 1, view: 'text', type: 'string' },
  productCode: { title: '商品编码', order: 2, view: 'text', type: 'string' },
  productBarcode: { title: '商品条码', order: 3, view: 'text', type: 'string' },
  width: { title: '宽', order: 4, view: 'number', type: 'number' },
  length: { title: '长', order: 5, view: 'number', type: 'number' },
  height: { title: '高', order: 6, view: 'number', type: 'number' },
  volume: { title: '体积', order: 7, view: 'number', type: 'number' },
  grossWeight: { title: '毛重', order: 8, view: 'number', type: 'number' },
  netWeight: { title: '净重', order: 9, view: 'number', type: 'number' },
  categoryId: { title: '商品一级分类id', order: 10, view: 'text', type: 'string' },
  packagingSpec: { title: '包装规格', order: 11, view: 'text', type: 'string' },
  maintenanceCycle: { title: '养护周期(天)', order: 12, view: 'number', type: 'number' },
  shelfLife: { title: '保质期(天)', order: 13, view: 'number', type: 'number' },
  unit: { title: '计量单位', order: 14, view: 'text', type: 'string' },
  isExpiryControlled: { title: '是否保质期管控', order: 15, view: 'list', type: 'string', dictCode: 'yn' },
  status: { title: '状态', order: 16, view: 'list', type: 'string', dictCode: 'wms_status' },
  supplierBarcode: { title: '供应商条码', order: 17, view: 'text', type: 'string' },
  productSpec: { title: '商品规格', order: 18, view: 'text', type: 'string' },
  productBatch: { title: '商品批次', order: 19, view: 'text', type: 'string' },
  productBrand: { title: '商品品牌', order: 20, view: 'text', type: 'string' },
};

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
